﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Threading;

namespace gui {

    /// <summary>
    /// GUI Notifiable Status Info Class
    /// Contains the status string and a boolean active property
    /// </summary>
    public class StatusInfo : DependencyObject {

        public static StatusInfo Instance;
        public static Dispatcher _Dispatcher { get; set; }

        public static DependencyProperty StatusProperty = DependencyProperty.Register("Status", typeof(string), typeof(StatusInfo));
        public static DependencyProperty IsActiveProperty = DependencyProperty.Register("IsActive", typeof(bool), typeof(StatusInfo));

        static StatusInfo() {
            Instance = new StatusInfo();
            Instance.Status = "Not Connected";
        }

        public string Status {
            get { return (string)GetValue(StatusProperty); }
            set { SetValue(StatusProperty, value); }
        }
        public bool IsActive {
            get { return (bool)GetValue(IsActiveProperty); }
            set { SetValue(IsActiveProperty, value); }
        }

        public static void SetStatus(string status) {
            if (status.Equals(null))
                Hide();

            if (_Dispatcher != null) {
                _Dispatcher.BeginInvoke(
                    DispatcherPriority.Send,
                    new Action(delegate() {
                    Instance.Status = status;
                    Instance.IsActive = true;
                }));
            }
        }

        public static void Hide() {
            if (_Dispatcher != null) {
                _Dispatcher.BeginInvoke(
                     DispatcherPriority.Send,
                    new Action(delegate() {
                    Instance.Status = string.Empty;
                    Instance.IsActive = false;
                }));
            }
        }
    }
}
